<template>
    <view-box v-if="addBasic" style="background:#F3F6F7;">
      <div style="height:10px;"></div>
      <div class="border-work">
        <x-input title="*公司名称:" v-model="addBasic.company"  placeholder="请输入公司" ></x-input>
        <div style="height:1px;width:92%;background:#f4f4f4;margin-left:4%;"></div>
        <x-input title="*公司行业:" v-model="addBasic.industry"  placeholder="请输入公司行业" ></x-input>
        <div style="height:1px;width:92%;background:#f4f4f4;margin-left:4%;"></div>
        <x-input title="*职位名称:" v-model="addBasic.job_title"  placeholder="职位名称" ></x-input>
        <div style="height:1px;width:92%;background:#f4f4f4;margin-left:4%;"></div>
        <datetime v-model="addBasic.start_time" :min-year=1960 :max-year=2050 format="YYYY-MM" @on-change="change" title="*开始时间 :"></datetime>
        <div style="height:1px;width:92%;background:#f4f4f4;margin-left:4%;"></div>
        <datetime v-model="addBasic.over_time" :min-year=1960 :max-year=2050 format="YYYY-MM" @on-change="change" title="*结束时间 :"></datetime>
        <x-input title="pid" v-model="addBasic.pid" style="display:none;"  placeholder="pid" ></x-input>
        <x-input title="pid" v-model="addBasic.uid" style="display:none;"  placeholder="pid" ></x-input>
      </div>
      <div style="height:10px;"></div>
      <div class="border-work">
        <p style="width:92%;margin-left:4%;color:#bababa;padding-top:5px;">职能业绩:</p>
        <x-textarea :max="200" placeholder="职能业绩" v-model="addBasic.performance" :show-counter="false" :height="60" :rows="8" :cols="30"></x-textarea>
      </div>
      <div style="height:10px;"></div>
      <div class="border-work">
        <x-input title="年薪:" v-model="addBasic.nianxin"  placeholder="例如：10-20万" ></x-input>
        <div style="height:1px;width:92%;background:#f4f4f4;margin-left:4%;"></div>
        <x-input title="公司性质:" v-model="addBasic.nature"  placeholder="公司性质" ></x-input>
        <div style="height:1px;width:92%;background:#f4f4f4;margin-left:4%;"></div>
        <x-input title="公司规模:" v-model="addBasic.scale"  placeholder="公司规模" ></x-input>
        <div style="height:1px;width:92%;background:#f4f4f4;margin-left:4%;"></div>
        <x-input title="所在部门:" v-model="addBasic.department"  placeholder="所在部门" ></x-input>
        <div style="height:1px;width:92%;background:#f4f4f4;margin-left:4%;"></div>
        <p style="width:92%;margin-left:4%;color:#bababa;padding-top:5px;">公司介绍:</p>
        <x-textarea :max="1000" placeholder="公司介绍" v-model="addBasic.company_introduction" :show-counter="false" :height="60" :rows="8" :cols="30"></x-textarea>
      </div>
        <div style="height:1px;width:100%;background:#f4f4f4"></div>
        <group style="width:92%;margin-left:4%;">
            <x-button style="background:#32B6C6;color:#fff;" @click.native="saveup()">确定</x-button>
        </group>
    </view-box>
</template>
<script>
import { ViewBox, Box, XInput, Group, XButton, Datetime, PopupPicker, ChinaAddressData, XHeader, XAddress, CheckIcon, XNumber, XTextarea } from 'vux'
export default {
  components: {
    ViewBox,
    Box,
    XInput,
    Group,
    XButton,
    Datetime,
    PopupPicker,
    XHeader,
    XAddress,
    CheckIcon,
    XNumber,
    XTextarea
  },
  data () {
    return {
      addressData: ChinaAddressData,
      radio001: ['是否统招'],
      value4: '',
      value3: '',
      value6: [['薪资面议', '1万-2万', '3万-5万', '5万-7万', '7万-10万', '10万-15万', '15万-20万', '200万-25万', '25万-30万', '30万-50万', '50万-100万']],
      addressValue: [],
      annual_salary: [],
      typec: [],
      value1: '',
      value12: [['在职，暂无跳槽打算', '在职，急寻新工作', '离职，正在找工作', '在职，看看新机会']],
      is_unified: false,
      pid: '',
      id: '',
      tabldata: {
        id: '',
        company: '',
        industry: '',
        job_title: '',
        start_time: '',
        over_time: ''
      },
      addBasic: {
        company: '',
        industry: '',
        job_title: '',
        start_time: ''
      },
      addiss: {},
      data: [],
      addpid: '',
      demo2: false,
      demo1: true
    }
  },
  computed: {
    disabled () {
      console.log('zunhh')
    },
    userInfo () {
      return this.$store.getters.userInfo
    }
  },
  mounted () {
    this._getconm()
    this._getresume()
    if (!this.$store.state.auth.userInfo) {
      this.$store.dispatch('getUserInfo')
    }
  },
  created () {
    if (this.$route.query.id !== null) {
      this.id = parseInt(this.$route.query.id)
    }
  },
  methods: {
    _getresume () {
      this.$http.get('/resume').then(response => {
        this.addpid = response.data.id
        if (this.$route.query.id > 0) {
          response.data.work.forEach((item) => {
            if (parseInt(item.id) === parseInt(this.$route.query.id)) {
              let obj = {
                pid: item.pid,
                uid: item.uid,
                company: item.company,
                industry: item.industry,
                job_title: item.job_title,
                start_time: item.start_time,
                over_time: item.over_time,
                performance: item.performance,
                report: item.report,
                subordinate_number: item.subordinate_number,
                nianxin: item.nianxin,
                nature: item.nature,
                scale: item.scale,
                department: item.department,
                company_introduction: item.company_introduction
              }
              this.data.push(obj)
              this.addBasic = this.data[0]
            }
          })
        }
        // console.log(this.addressValue)
      }).catch(error => {
        console.log(error)
      })
    },
    change () {
      console.log('zhou')
    },
    saveup () {
      if (this.$route.query.id !== undefined) {
        this.updata()
      } else {
        this.save()
      }
    },
    save () {
      if (this.addBasic.company === '') {
        this.$vux.toast.show({
          text: '公司不能为空',
          type: 'text'
        })
        return false
      }
      if (this.addBasic.industry === '') {
        this.$vux.toast.show({
          text: '公司行业不能为空',
          type: 'text'
        })
        return false
      }
      if (this.addBasic.job_title === '') {
        this.$vux.toast.show({
          text: '职位名称不能为空',
          type: 'text'
        })
        return false
      }
      let data = {
        uid: this.userInfo.id ? this.userInfo.id : 0,
        pid: this.addpid,
        company: this.addBasic.company,
        industry: this.addBasic.industry,
        job_title: this.addBasic.job_title,
        start_time: this.addBasic.start_time,
        over_time: this.addBasic.over_time,
        performance: this.addBasic.performance,
        report: this.addBasic.report,
        subordinate_number: this.addBasic.subordinate_number,
        nianxin: this.addBasic.nianxin,
        nature: this.addBasic.nature,
        scale: this.addBasic.scale,
        department: this.addBasic.department,
        company_introduction: this.addBasic.company_introduction
      }
      this.$http.post('/resume/storeWork', data).then(response => {
        this.$vux.toast.show({
          text: response.data.message,
          type: 'text'
        })
        this.$router.push({ path: '/myresume' })
        console.log(response)
      }).catch(error => {
        console.log(error)
      })
    },
    updata () {
      let data = {
        id: this.$route.query.id,
        company: this.addBasic.company,
        industry: this.addBasic.industry,
        job_title: this.addBasic.job_title,
        start_time: this.addBasic.start_time,
        over_time: this.addBasic.over_time,
        performance: this.addBasic.performance,
        report: this.addBasic.report,
        subordinate_number: this.addBasic.subordinate_number,
        nianxin: this.addBasic.nianxin,
        nature: this.addBasic.nature,
        scale: this.addBasic.scale,
        department: this.addBasic.department,
        company_introduction: this.addBasic.company_introduction
      }
      this.$http.put('/resume/updateWork', data).then(response => {
        this.$vux.toast.show({
          text: response.data.message,
          type: 'text'
        })
        this.$router.push({ path: '/myresume' })
        console.log(response)
      }).catch(error => {
        console.log(error)
      })
    },
    setDefaults () {
      console.log(1)
    },
    _getconm () {
      this.$http.post('/entrance').then(response => {
        this.pid = response.data.data.id
      })
    }
  }
}
</script>

<style scoped>
    .btn-set-default {
        flex: 1;
        line-height: 50px;
        
    }
    .border-work{
       width: 92%;
      margin-left: 4%;
      background: #fff;
      border-radius: 7px;
    }
</style>
<style>
.wiadd.weui-cell_access {
    font-size: 16px;
}
.weui-cells__title {
    margin-top: 0.77em;
    margin-bottom: 0.3em;
    padding-left: 15px;
    padding-right: 15px;
    color: #000 !important;
    font-size: 16px !important;
}
 .weui-cells:before{
        border-top: 0px solid #D9D9D9 !important;
    }
    .weui-cells:after{
        border-bottom: 0px solid #D9D9D9 !important;
    }
  .border-work .weui-cell_access {
    font-size: 16px!important;
  }
  .border-work .vux-datetime {
    color: #bababa;
  }
  .border-work .weui-label {
    display: block;
    width: 105px;
    word-wrap: break-word;
    word-break: break-all;
    color: #AEB1B2;
}
.weui-cell:before {
    border-top: 0px solid #D9D9D9!important;
}
.border-work .weui-cell p{
  color:#AEB1B2;
}
</style>
